<?php

abstract class OOWP_Controller
    extends OOWP_Base
{

    public function __construct(array $args = array( ))
    {
        global $wp_query;

        $input = array_merge(array(
            'body' => new OOWP_Element_Body( ),
            'head' => new OOWP_Element_Head( ),
            'query' => $wp_query,
        ), $args);

        parent::__construct($input);

        $this->dict['html'] = new OOWP_Element_Html(array(
            'contents' => array(
                $this->head,
                $this->body,
            ),
        ));
    }

    /* ACCESSORS */

    protected function getBody( )
    {
        return $this->dict['body'];
    }

    protected function setBody(OOWP_Element_Body $body)
    {
        $this->dict['body'] = $body;
    }

    protected function getHead( )
    {
        return $this->dict['head'];
    }

    protected function setHead(OOWP_Element_Head $head)
    {
        $this->dict['head'] = $head;
    }

    protected function getHtml( )
    {
        return $this->dict['html'];
    }

    protected function getQuery( )
    {
        return $this->dict['query'];
    }

    protected function setQuery(WP_Query $query)
    {
        $this->dict['query'] = $query;
    }

    /* METHODS */

    public function format( )
    {
        return implode("\n", $this->html->format( ));
    }

    abstract static function matches(WP_Query $query);

}
